import { YamlReader, path } from '#auth'
import { join } from 'path'

const configPath = join(path, 'config', 'config', 'other.yaml')

/**
 * 增加或删除群黑白名单
 * @param {string|number} group_id 群号
 * @param {'blackGroup'|'whiteGroup'} key 
 * @param {'add'|'del'} type 执行的操作
 */
function setBlockOrWhite(group_id, key, type = 'add') {
    let yaml = new YamlReader(configPath)
    if (type == 'add') {
        yaml.addIn(key, group_id)
    } else {
        let index = yaml.jsonData[key].indexOf(group_id)
        yaml.delete(`${key}.${index}`)
    }
}

export {
    setBlockOrWhite
}